const { Router } = require('express')
const express = require('express')
//路由容器
const expressmessage = express.Router()
const axios = require('axios')
const { JsonWebTokenError } = require('jsonwebtoken')
const jwt = require("jsonwebtoken")
expressmessage.post('/refuseExpress/addRefuseExpress', (req, res) => {
    let {expressId,orderId,reason,userId}=req.body.params
    axios({
        method:'post',
        url : '/refuseExpress/addRefuseExpress',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            token:req.session.token
        },
        params:{
            expressId:expressId,
            orderId:orderId,
            reason:reason,
            userId:jwt.decode(req.session.token).id
     }
    }).then(function(data){
        res.status(200).json({
            data:data.data,
            code:0
        })
    }).catch(function(err){
        res.status(500).json({
            msg:'失败'
        })
    })
 })
 expressmessage.post('/refund/addRefund', (req, res) => {
    let {expressId,orderId,reason}=req.body.params
    axios({
        method:'post',
        url : '/refund/addRefund',
        params:{
            expressId:expressId,
            orderId:orderId,
            reason:reason
     }
    }).then(function(data){
        res.status(200).json({
            data:data.data,
            code:0
        })
    }).catch(function(err){
        res.status(500).json({
            msg:'失败'
        })
    })
 })
 expressmessage.get('/express/selectInformationInExpress', (req, res) => {
    let {expressId}=req.query
   axios({
       method:'get',
       url : '/express/selectInformationInExpress',
       params:{
        expressId:expressId
    }
   }).then(function(data){
       res.status(200).json({
           data:data.data,
           code:0
       })
   }).catch(function(err){
        console.log(err)
        res.status(500).json({
           msg:err
       })
   })
})
expressmessage.get('/express/userSureOrNoSent', (req, res) => {
    let {pageNo,pageSize,userId}=req.query
   axios({
       method:'get',
       url : '/express/userSureOrNoSent',
       headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        token:req.session.token
    },
       params:{
        pageSize:pageSize,
        pageNo:pageNo,
        userId:jwt.decode(req.session.token).id
    }
   }).then(function(data){
       res.status(200).json({
           data:data.data,
           code:0
       })
   }).catch(function(err){
        console.log(err)
        res.status(500).json({
           msg:err
       })
   })
})

module.exports= expressmessage;